<?php
    $titlePage = @$this->enterprise->company_name_vn.': '.@$this->set->title.'-'.@$this->photos[0]->title;
    $this->headTitle(@$titlePage);

    $this->headLink()
        ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
        ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
        ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
        ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css');

    $this->headScript()
        ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
        ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
		->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.droppable.js')
		->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
        ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js');
?>
<style>
    .b_a_right{
        text-align: right;
    }
    .g_content{

    }
    .col_20{
        float: left;
        width: 20%;
    }
    .g_content{
        padding : 10px 0 0 0;
    }
    .g_content .g_image{
        text-align: center;
    }
    .g_content .subcolumns{
        padding: 0 0 10px 0;
    }
    .b_a_right span{
        padding: 0 0 0 7px;
    }
    .b_bottom{
        margin-bottom: 10px;
    }
    .b_breadcrumb{
        display: inline-block;
        width:100%;
    }
</style>
<?php
    $skin_url = $this->APP_STATIC_SERVER . '/skins/'. $this->APP_TEMPLATE . '/'. $this->APP_SKIN;
?>
<div class="grid_12">
    <div class="grid_8 alpha">
        <?php if(!$this->found):?>
        <?php echo $this->translator('not_found_database');?>
        <?php else:?>
        <!--Sub menu-->
        <?php echo $this->widget('bizprofile','menu',array()); ?>
        <!--End sub menu-->
        <div class="subcolumns pb10">
            <?php if(count($this->photos) <= 0):?>
                <?php echo $this->translator('gallery_not_found_item');?>
            <?php else:?>
            
            <div class="b_breadcrumb b_bottom">
                <!--form edit-->
                <?php
                    $arrRouteList = array(
                        'enterprise_id' => $this->enterprise->id,
                        'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true),
                    );
                
                    $arrRouteAlbum = array(
                        'enterprise_id' => $this->enterprise->id,
                        'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true),
                        'slug' => $this->set->slug,
                        'set_id' => $this->set->set_id
                    );
                ?>
                <div style="width:70%; float:left; display:none;" id="hd_form">
                    <?php if($this->allow('edit-detail') && $this->allowAction):?>
                    <form action="#" method="post" id="formEditDetail" onkeypress="return event.keyCode!=13">
                        <a href="<?php echo $this->url($arrRouteList, 'b2b_gallery_list');?>"><?php echo $this->translator('gallery_list_breadcrumb');?></a> »
                        <a href="<?php echo $this->url($arrRouteAlbum, 'b2b_gallery_album');?>"><?php echo $this->set->title;?></a> »
                        <input type="hidden" value="<?php echo $this->photos[0]->file_id;?>" name="file_id" />
                        <input type="text" value="<?php echo $this->photos[0]->title;?>" name="file_title" id="file_title"/>
                        <img id="btn_unedit" title="<?php echo $this->translator('gallery_edit_detail');?>" style="cursor:pointer" src="<?php echo $skin_url;?>/images/edit.png" />
                    </form>
                    <?php endif;?>
                </div>
                <div style="width:70%; float:left;" id="div_unform">
                    <a href="<?php echo $this->url($arrRouteList, 'b2b_gallery_list');?>"><?php echo $this->translator('gallery_list_breadcrumb');?></a> »
                    <a href="<?php echo $this->url($arrRouteAlbum, 'b2b_gallery_album');?>"><?php echo $this->set->title;?></a> »
                    <label id="lb_title"><?php echo $this->photos[0]->title;?></label>
                    <?php if($this->allow('edit-detail') && $this->allowAction):?>
                    <img class="btn_edit" title="<?php echo $this->translator('gallery_edit_detail');?>" style="cursor:pointer" src="<?php echo $skin_url;?>/images/edit.png" />
                    <?php endif;?>
                </div>
                <!--end form edit-->

				<?php
                	$arrRouteMark = array(
                		'enterprise_id' => $this->enterprise->id,
                        'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true),
                        'slug' => $this->set->slug,
                        'set_id' => $this->set->set_id,
                        'file_id' => $this->photos[0]->file_id
                    );
                ?>
                <div style="width:30%; float:left; text-align:right;">
                    
                	<!--<?php if($this->allow_mark==1):?>
                		<?php if($this->checkmark==0){?>
	                    	<?php  if ($this->allow('mark')) : ?>
								<div id="Mark">
	                    			<a class="markAction" rel="<?php echo $this->photos[0]->file_id ;?>" href="javascript: void(0);">Mark</a>
	                    		</div>
	                    	<?php  endif;?>
	                    <?php }
	                    	  if($this->checkmark==1){?>
	                    		<div id="Unmark">
					        	<a href="<?php echo $this->url($arrRouteMark, 'b2b_gallery_unmark');?>">Unmark</a>
					        	</div>
				        <?php }?>
                	<?php endif;?>-->
                	<div style="float: right; padding-bottom: 5px;">
                		&nbsp;&nbsp; | &nbsp;
                		<?php if($this->allow('edit-detail') && $this->allowAction):?>
		                <a class="btn_edit" href="javascript:void(0)"><?php echo $this->translator('gallery_detail_edit')?></a>&nbsp;&nbsp;
		                <?php endif;?> | &nbsp;
		                <?php if($this->allow('delete-file') && $this->allowAction):?>
		                <a id="btn_del_file" href="javascript:void(0)"><?php echo $this->translator('gallery_detail_delete')?></a>
		                <?php endif;?>
                	</div>
                	
                	<?php if($this->allow_mark==1):?>                		
	                    	<?php  if ($this->allow('mark')) : ?>
								<div id="Mark" style=" padding-bottom: 5px;">
									<?php if($this->checkmark==0):?>
	                    			<a class="markAction" val="mark" rel="<?php echo $this->photos[0]->file_id ;?>" href="javascript: void(0);">
	                    				<span id="actionLabel">
	                    					<?php echo $this->translator('gallery_mark_image');?>
	                    				</span>
	                    			</a>
	                    			<?php else:?>
	                    			<a class="markAction" val="unmark" rel="<?php echo $this->photos[0]->file_id ;?>" href="javascript: void(0);">
	                    				<span id="actionLabel">
	                    					<?php echo $this->translator('gallery_unmark_image');?>
	                    				</span>
	                    			</a>
	                    			<?php endif;?>
	                    		</div>
	                    	<?php endif;?>
                	<?php endif;?>
                	
                	<?php
                        $count = $this->numPhoto;
                        $pageIndex = $this->pageIndex;
                        $preIndex = ($pageIndex == 1)?$count:$pageIndex-1;
                        $nextIndex = ($pageIndex == $count)?1:$pageIndex+1;

                        /**
                        * Array param required for url
                        **/
                        $arrRouteDetailPre = array(
                            'enterprise_id' => $this->enterprise->id,
                            'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true),
                            'slug' => $this->set->slug,
                            'set_id' => $this->set->set_id,
                            'pageIndex' => $preIndex,
                            'image_slug' => 'pre'
                        );

                        $arrRouteDetailNext = array(
                            'enterprise_id' => $this->enterprise->id,
                            'enterprise_name' => Tomato_Utility_String::removeSign($this->enterprise->company_name_en, '-', true),
                            'slug' => $this->set->slug,
                            'set_id' => $this->set->set_id,
                            'pageIndex' => $nextIndex,
                            'image_slug' => 'next'
                        );

                        /**
                        * Image to view;
                        **/
                        $photo = $this->photos[0];
                    ?>
                    <a href="<?php echo $this->url($arrRouteDetailPre, 'b2b_gallery_detail');?>">« <?php echo $this->translator('gallery_pre_page');?></a>
                    &nbsp;&nbsp;&nbsp;
                    <a href="<?php echo $this->url($arrRouteDetailNext, 'b2b_gallery_detail');?>"><?php echo $this->translator('gallery_next_page');?> »</a>
                </div>
            </div>

            <div class="g_content">
                <?php

                    /**
                    * Check exist image
                    **/
                    $file    = $photo->image_large;
                    $path    = str_replace($this->APP_STATIC_SERVER,getcwd(),$file);
                    $image = (is_file($path))?$file:null;
                ?>
                <div>
                    <div class="clearfix">
                        <span><a href="<?php echo $this->url($arrRouteDetailNext, 'b2b_gallery_detail');?>"><img width="640" src="<?php echo $image;?>" /></a>
                    </div>
                    <!--<div class="clearfix">
                        <?php echo $photo->title;?>
                    </div>-->
                </div>
            </div>
            <div class="b_a_right">
                <a href="<?php echo $this->url($arrRouteDetailPre, 'b2b_gallery_detail');?>">« <?php echo $this->translator('gallery_pre_page');?></a>
                &nbsp;&nbsp;&nbsp;
                <a href="<?php echo $this->url($arrRouteDetailNext, 'b2b_gallery_detail');?>"><?php echo $this->translator('gallery_next_page');?> »</a>
            </div>

            <div id="messageDialog"></div>
            <div id="confirmDialog"></div>
            

            <script type="text/javascript" src="<?php echo $this->APP_STATIC_SERVER; ?>/js/jquery.form/jquery.form.js"></script>
            <script type="text/javascript">
                $(document).ready(function() {

                    $('.btn_edit').click(function(){
                        $('#hd_form').show();
                        $('#div_unform').hide();
                        $('#file_title').focus();
                    });
                    $('#btn_unedit').click(function(){
                        file_title = $('#file_title').val();
                        $('#lb_title').text(file_title);

                        $('#hd_form').hide();
                        $('#div_unform').show();
                    });

                    /**
                    * Ajax submit form
                    */
                    var options = {
                        target: '#outPut', // target element(s) to be updated with server response
                        beforeSubmit:  showRequest,
                        url: '<?php echo $this->url(array(), 'b2b_gallery_detail_edit');?>',
                        type: 'POST',  // pre-submit callback,
                        success: function(){
                        }
                    };
                    $('#file_title').blur(function(){
                        file_title = $('#file_title').val();
                        file_title = file_title.replace(/^\s+|\s+$/g, '');
                        if(file_title != ''){
                            $("#formEditDetail").ajaxSubmit(options);

                            /**
                            * Update action
                            */
                            file_title = $('#file_title').val();
                            $('#lb_title').text(file_title);
                            $('#hd_form').hide();
                            $('#div_unform').show();
                        }else{
                            return false;
                        }
                    });

                    $('#file_title').keypress(function(e){
                        if(e.which == 13){
                            file_title = $('#file_title').val();
                            file_title = file_title.replace(/^\s+|\s+$/g, '');
                            if(file_title != ''){
                                $("#formEditDetail").ajaxSubmit(options);

                                /**
                                * Update action
                                */
                                file_title = $('#file_title').val();
                                $('#lb_title').text(file_title);
                                $('#hd_form').hide();
                                $('#div_unform').show();
                            }else{
                                return false;
                            }
                        }
                    });


                    /**
                    * Delete file
                    */
                    $('#btn_del_file').click(function(){
                        var self = this;
                        $('#confirmDialog').html('<?php echo addslashes($this->translator('gallery_view_action_delete_file_confirm')); ?>')
                            .dialog({
                                title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
                                dialogClass: 't_a_ui_dialog',
                                modal: true,
                                closeOnEscape: false,
                                resizable: false,
                                open: function(event, ui) {
                                    $('.ui-dialog-titlebar-close').hide();
                                    $(this).parent().find('.ui-dialog-buttonpane button').wrapInner('<span/>');
                                },
                                buttons: {
                                    '<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
                                        $(this).dialog('destroy');
                                    },
                                    '<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
                                        $(this).dialog('destroy');
                                        window.location = '<?php echo $this->url(array('enterprise_id' => $this->enterprise->id,'set_id'=>$this->set->set_id, 'file_id' => $this->photos[0]->file_id), 'b2b_gallery_delete_file')?>';
                                    }
                                }
                        });
                    });
                    /**End delete file*/
                    
                    /* MArk image*/
                    <?php if ($this->allow('mark')) : ?>
                    $('a.markAction').click(function() {
						var self = this;
						
						val = $(self).attr('val');
						
						//$(this).dialog('destroy');
						//$(self).html('').addClass('t_a_ui_helper_loading');
						var file_id = $(self).attr('rel');
										
						$.ajaxq('b2b', 
						{
							type: 'POST',
							url: "<?php echo $this->url(array(), 'b2b_gallery_mark'); ?>",
							data: { file_id: file_id , type: val},
							success: function(response) 
							{	
								if ('RESULT_OK' == response) 
								{
									//$(self).removeClass('t_a_ui_helper_loading');
									//$('#Mark').fadeOut('slow');
									//$('#Unmark').fadeIn('slow');
									
									/**
									* Update type
									*/
									if(val == 'mark'){
										$('#actionLabel').text("<?php echo $this->translator('gallery_unmark_image');?>");
										$(self).attr('val', 'unmark');
									}else{
										$('#actionLabel').text("<?php echo $this->translator('gallery_mark_image');?>");
										$(self).attr('val', 'mark');
									}
								}
							}
						});
					});
					<?php endif;?>
					/*End mark image*/

                })

                function showRequest(formData, jqForm, options) {
                    var queryString = $.param(formData);
                    return true;
                }
            </script>

            <?php endif;?>
        </div>
        <?php endif;?>
    </div>
    <div class="grid_4 omega">
        <?php echo $this->widget('bizprofile','map',array()); ?>
        <?php echo $this->widget('bizprofile','help',array()); ?>
    </div>
</div>
<div class="grid_12">
    <?php echo $this->widget('bizprofile','contact',array()); ?>
</div>